﻿using System.Linq;
using System.Web.DomainServices;
using System.Web.DomainServices.Providers;
using System.Web.Ria;
using SoftSource.Timecard.Web.Data;

namespace SoftSource.Timecard.Web.Services
{
    [EnableClientAccess]
    [RequiresAuthentication]
    [RequiresRole("Administrator")]
    public class CustomerService : LinqToSqlDomainService<CustomerDBDataContext>
    {
        #region Customers
        public IQueryable<Customer> GetCustomers()
        {
            return this.DataContext.Customers;
        }

        public void InsertCustomer(Customer customer)
        {
            this.DataContext.Customers.InsertOnSubmit(customer);
        }

        public void UpdateCustomer(Customer currentCustomer)
        {
            this.DataContext.Customers.Attach(currentCustomer, this.ChangeSet.GetOriginal(currentCustomer));
        }

        public void DeleteCustomer(Customer customer)
        {
            this.DataContext.Customers.Attach(customer);
            this.DataContext.Customers.DeleteOnSubmit(customer);
        }
        #endregion Customers

        #region Customer Users
        public IQueryable<CustomerUser> GetCustomerUser()
        {
            return this.DataContext.CustomerUsers;
        }

        public void InsertCustomerUser(CustomerUser customerUser)
        {
            this.DataContext.CustomerUsers.InsertOnSubmit(customerUser);
        }

        public void UpdateCustomerUser(CustomerUser currentCustomerUser)
        {
            this.DataContext.CustomerUsers.Attach(currentCustomerUser, this.ChangeSet.GetOriginal(currentCustomerUser));
        }

        public void DeleteCustomerUser(CustomerUser customerUser)
        {
            this.DataContext.CustomerUsers.Attach(customerUser);
            this.DataContext.CustomerUsers.DeleteOnSubmit(customerUser);
        }
        #endregion Customer Users

        #region Customer Projects
        public IQueryable<CustomerProject> GetCustomersProjects()
        {
            return this.DataContext.CustomerProjects;
        }

        public void InsertCustomerProject(CustomerProject customerProject)
        {
            this.DataContext.CustomerProjects.InsertOnSubmit(customerProject);
        }

        public void UpdateCustomerProject(CustomerProject currentCustomerProject)
        {
            this.DataContext.CustomerProjects.Attach(currentCustomerProject, this.ChangeSet.GetOriginal(currentCustomerProject));
        }

        public void DeleteCustomerProject(CustomerProject customerProject)
        {
            this.DataContext.CustomerProjects.Attach(customerProject);
            this.DataContext.CustomerProjects.DeleteOnSubmit(customerProject);
        }
        #endregion Customer Projects
    }
}


